/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package BUS;
import POJO.HocSinhPOJO;
import DAO.HocSinhDAO;
import DAO.QuyDinhDAO;
import POJO.QuyDinhPOJO;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;


/**
 *
 * @author MinhHieu
 */
public class HocSinhBUS {

    public static  ArrayList<HocSinhPOJO> search(String MaHocSinh, String TenHocSinh,String GioiTinh, String NgaySinh, String DiaChi, String Email, boolean type){
        ArrayList<HocSinhPOJO> list = HocSinhDAO.search(MaHocSinh, TenHocSinh, GioiTinh, NgaySinh, DiaChi, Email, type);
        return list;
    }

    public static  ArrayList<HocSinhPOJO> selectHocSinh_KoLop(){
        ArrayList<HocSinhPOJO> list = HocSinhDAO.selectHocSinh_KoLop();
        return list;
    }
    public static  ArrayList<HocSinhPOJO> selectHocSinh_Lop(String MaLop){
        ArrayList<HocSinhPOJO> list = HocSinhDAO.selectHocSinh_Lop(MaLop);
        return list;
    }
    public static  ArrayList<HocSinhPOJO> layhocsinh(){
        ArrayList<HocSinhPOJO> list = HocSinhDAO.layhocsinh();
        return list;
    }
    public static  boolean themHS(String maHS,String tenHS,String ngaysinh,String gioitinh,String diachi,String email){
        boolean kq = false;
        QuyDinhPOJO qd = QuyDinhDAO.selectAll();
        //lay nam he thong....
        Date d=new Date(System.currentTimeMillis());
        SimpleDateFormat dayFormat= new SimpleDateFormat("yyyy");
        int thisyear = Integer.parseInt(dayFormat.format(d.getTime()));
        // cat chuoi....
        String[] Temp = ngaysinh.split("-");
        int NamSinh = Integer.parseInt(Temp[0]);
        //so sanh
        int Tuoi = thisyear - NamSinh;
        if(Tuoi >= qd.getTuoiMin() && Tuoi <= qd.getTuoiMax()){
            kq = HocSinhDAO.ThemHocSinh(maHS,tenHS, ngaysinh, gioitinh, diachi, email);
        }
        return kq;
    }
    public static boolean  suaHS(String mHS, String tenHS,String ns,String gioitinh,String dc,String email){
        boolean kq =false;
        // Lay quy dinh
        QuyDinhPOJO qd = QuyDinhDAO.selectAll();
        //Lay gio he thong
        Date d = new Date(System.currentTimeMillis());
        SimpleDateFormat dayFormat= new SimpleDateFormat("yyyy");
        int thisyear = Integer.parseInt(dayFormat.format(d.getTime()));
        //cat chuoi
        String[] Temp = ns.split("-");
        int NamSinh = Integer.parseInt(Temp[0]);
        //so sanh
        int Tuoi = thisyear - NamSinh;
        if(Tuoi >= qd.getTuoiMin() && Tuoi <=qd.getTuoiMax()){
            kq = HocSinhDAO.suaHs(mHS, tenHS, ns,gioitinh,dc, email);
        }
        return kq;
    }
     public static boolean  xoaHS(String mhs){
        boolean kq = HocSinhDAO.XoaHS(mhs);
        return kq;
    }
}